<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-block">
                    <select class="chosen-select" name="parentid">
                        <option value="0">顶级菜单</option>
                        <{foreach from=$topmenus item=item}>
                        <option value="<{$item->id}>"
                        <{if $item->id eq $parent_id}>selected="selected"<{/if}>
                        <{if isset($data)}><{if $data->parentid eq $item->id }>selected="selected"<{/if}><{/if}>
                        ><{$item->title}></option>
                        <{/foreach}>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="<{if isset($data)}><{$data->title}><{/if}>"
                           lay-verify="required"
                           placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择URI</label>
                <div class="layui-input-block">
                    <select class="chosen-select" name="url" lay-search>
                        <{foreach $all_actions as $mod=>$module}>
                        <{foreach from=$module item=controller key=con}>
                        <{foreach from=$controller item=act}>
                        <option value="<{$mod}>/<{$con}>/<{$act}>"
                        <{if isset($data) && strtolower($data->url) eq "$mod/$con/$act"}>selected<{/if}>
                        ><{$mod}>/<{$con}>/<{$act}></option>
                        <{/foreach}>
                        <{/foreach}>
                        <{/foreach}>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">ICON</label>
                <div class="layui-input-block">
                    <input type="text" name="icon" id="iconPicker"
                           value="<{if isset($data)}><{$data->icon}><{else}>layui-icon-home<{/if}>"
                           lay-verify="required" placeholder="icon" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权重</label>
                <div class="layui-input-block">
                    <input type="text" name="sort"
                           value="<{if isset($data)}><{$data->sort}><{else}>0<{/if}>"
                           lay-verify="number" placeholder="数字越大越靠前" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="form-submit" id="form-submit"
                       value="确认">
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form','element','iconPickerFa'], function () {
        var $ = layui.$
            , form = layui.form
            , element = layui.element
            ,iconPickerFa = layui.iconPickerFa;

        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // fa 图标接口
            url: "lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
                console.log(d);
            }
        });

        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/id/<{if isset($data)}><{$data->id}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    layui.table.reload('table-page'); //重载表格
                    layer.close(parentIndex); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>